﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Web.Admin.Config
{
    public partial class SiteMap : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            BaseCode.SiteMapProvider siteMap = new BaseCode.SiteMapProvider(true);
            siteMap.AddUrl(BaseCode.BlogPageType.Home, BaseCode.CommValue.Domain, DateTime.Now);

            //添加文章链接
            BLL.BLL_Article articleBll = new BLL.BLL_Article();
            string str = string.Format("state > 0 and publishtime <=#{0}#", System.DateTime.Now.ToString("yyyy-MM-dd"));
            List<Model.Model_Article> articles = articleBll.GetModelList(str);
            
            for (int i = 0; i < articles.Count; i++)
            {
                siteMap.AddUrl(BaseCode.BlogPageType.Article, articles[i].ename, articles[i].updatetime);
            }

            //添加分类及标签链接
            BLL.BLL_Tags tagsBll = new BLL.BLL_Tags();
            List<Model.Model_Tags> tagList = tagsBll.GetModelList("state>0");
            for (int i = 0; i < tagList.Count; i++)
            {
                if(tagList[i].tagtype == BaseCode.CommValue.ArticleClass)
                    siteMap.AddUrl(BaseCode.BlogPageType.Category, tagList[i].ename, tagList[i].updatetime);
                else
                    siteMap.AddUrl(BaseCode.BlogPageType.Tag, tagList[i].ename, tagList[i].updatetime);
            }

            this.Label1.Text = string.Format("链接共{0}个,文章连接共{1}个,标签共{2}个", articles.Count + tagList.Count, articles.Count, tagList.Count);
        }
    }
}